package cn.hgy.domain.activity.service.discount.impl;

import cn.hgy.domain.activity.model.valobj.GroupBuyActivityDiscountVO;
import cn.hgy.domain.activity.service.discount.AbstractDiscountCalculateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service("ZJ")
@Slf4j
public class ZJCalculateService extends AbstractDiscountCalculateService {
    @Override
    protected BigDecimal doCalculate(BigDecimal originalPrice, GroupBuyActivityDiscountVO.GroupBuyDiscount groupBuyDiscount) {
        String marketExpr = groupBuyDiscount.getMarketExpr();

        // 市场表达式格式为：原价-减免金额
        BigDecimal deductionPrice = originalPrice.subtract(new BigDecimal(marketExpr));

        // 如果减免后的价格小于等于0，则返回0.01元
        if (deductionPrice.compareTo(BigDecimal.ZERO) <= 0) return new BigDecimal("0.01");

        return deductionPrice;
    }
}
